﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using WeifenLuo.WinFormsUI.Docking;

namespace Frame
{
    /// <summary>
    /// 框架应用
    /// </summary>
    public class FrameApplication
    {
        public event Action StartEvent;
        public event Action EndEvent;
        /// <summary>
        /// 初始化窗口事件
        /// </summary>
        public event Action InitialUiEvnet;

        private object mutex;



        public PluginManager PluginManager { get; }
        public Log Log { get; }
        public ErrorMessage ErrorMessage { get; }
        public ApplicationManager ApplicationManager { get; }
        public Form MainForm { get; }

        public FrameApplication(Form mainForm)
        {
            mutex = new object();
            this.MainForm = mainForm;
            this.Log = new Log(this);//消息类

            this.PluginManager = new PluginManager(this);//窗口管理类
            this.ErrorMessage = new ErrorMessage(this);//错误码解析
            this.ApplicationManager = new ApplicationManager();
        }

        private FrameApplication(FrameApplication app)
        {
            mutex = new object();
            this.MainForm = app.MainForm;
            this.Log = app.Log;
            this.PluginManager = app.PluginManager;
            this.ErrorMessage = app.ErrorMessage;//错误码解析
            this.ApplicationManager = app.ApplicationManager;
        }


        public void OnStartEvent()
        {
            if (StartEvent != null)
            {
                if (MainForm.InvokeRequired)
                {
                    MainForm.Invoke(new Action(OnStartEvent));
                }
                else
                {
                    StartEvent();
                }
            }
        }
        public void OnEndEvent()
        {
            if (EndEvent != null)
            {
                if (MainForm.InvokeRequired)
                {
                    MainForm.Invoke(new Action(OnEndEvent));
                }
                else
                {
                    EndEvent();
                }
            }
        }

        public void OnInitialUiEvnet()
        {
            if(InitialUiEvnet != null)
            {
                if(MainForm.InvokeRequired)
                {
                    MainForm.Invoke(InitialUiEvnet);
                }
                else
                {
                    InitialUiEvnet();
                }
            }
        }

    }
}

